import 'dart:async';

import 'package:flutter/material.dart';
import 'package:gold/app/user_provider.dart';
import 'package:gold/ui/goods/goods_home_page.dart';
import 'package:gold/ui/home/home_page.dart';
import 'package:gold/ui/my/my_page.dart';
import 'package:gold/utils/cache_data.dart';
import 'package:gold/widgets/bottom_bar.dart';
import 'package:provider/provider.dart';

/// @description: 首页
/// @author tangzhentao
/// @created at 18:22 2024/11/24

class IndexPage extends StatefulWidget {
  const IndexPage({super.key});

  @override
  State<StatefulWidget> createState() => _IndexState();
}

class _IndexState extends State<IndexPage> {
  late final PageController pageController;

  @override
  void initState() {
    pageController = PageController();
    _loadConfig();
    super.initState();
  }

  /// 加载配置
  Future _loadConfig() async {
    context.read<UserProvider>().updateProfile();
    CacheData().setCollateralRate();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        extendBody: true,
        body: Column(
          children: [
            Expanded(
              child: PageView(
                physics: const NeverScrollableScrollPhysics(),
                controller: pageController,
                children: [
                  const HomePage(),
                  const GoodsHomePage(),
                  Container(),
                  const MyPage()
                ],
              ),
            ),
            BottomBar(pageController: pageController),
          ],
        )
    );
  }
}
